#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define BEGINS(x) namespace x {
#define ENDS(x) } // end of namespace x

BEGINS(test1)
class Base {
public:
    virtual void func1() {
        cout << "Base func1" << endl;
    }
    virtual void func2() {
        cout << "Base func2" << endl;
    }
    virtual void func3() {
        cout << "Base func3" << endl;
    }
    virtual ~Base() {}
};

class A : public Base {
public:
    void func2() override {
        cout << "A func2" << endl;
    }
    int x;
};

class B : public Base {
public:
    void func1() override {
        cout << "B func1" << endl;
    }
    void func3() override {
        cout << "B func3" << endl;
    }
    int x;
};

typedef void (*func)();

int main() {
    A a;

    a.func1();
    a.func2();
    ((func**)(&a))[0][0]();
    ((func**)(&a))[0][1]();

    B b;
    b.func1();
    b.func2();
    b.func3();
    ((func**)(&b))[0][0]();
    ((func**)(&b))[0][1]();
    ((func**)(&b))[0][2]();

    return 0;
}

ENDS(test1)

BEGINS(test2)
class Base {
public:
    virtual void func(int x) {
        cout << this << " : class Base " << x << endl;
    }
    virtual ~Base() {}
};

class A : public Base {
public:
    void func(int x) override {
        cout << "this->x = " << this->x << endl;
        cout << this << " : class A " << x << endl;
    }
    int x;
};

typedef void (*func)(void *, int);

int main() {
    A a;
    a.x = 100;

    a.func(1);
    ((func **)(&a))[0][0](&a, 1);

    return 0;
}

ENDS(test2)

int main() {
//    test1::main();
    test2::main();
    return 0;
}